package globalstruct

import (
	"time"
)

//网络信息接口
type SocketInfo struct {
	ID         uint      `json:"id"  db:"id"`
	Mac        string    `json:"GwMac"  db:"gwmac"`
	Family     string    `json:"family"  db:"family"` //源socket的IP协议
	IPAddr     string    `json:"IPAddr" db:"ipaddr"`  //源socket的IP
	IPPort     int       `json:"IPPort"  db:"ipport"` //源socket的port
	UpdateTime time.Time `json:"updateTime" db:"updatetime"`
}

//HTTP请求所用
//ap信息
type DeviceInfo struct {
	DeviceSN     string `json:"deviceSN"`
	OnlineStatus int    `json:"onlineStatus"`
}

//终端信息
type BleDeviceInfo struct {
	DeviceSN     string `json:"deviceSN"`
	OnlineStatus string `json:"onlineStatus"`
}

//网关插卡信息
type IotModuleInfo struct {
	PortId          int    `json:"PortID"`
	ModelType       string `json:"Model"` //模块型号
	SN              string `json:"SN"`    //模块序列
	MAC             string `json:"MAC"`   //模块mac
	GwMac           string `json:"GwMac"`
	IotModuleId     uint16 `json:"iotModuleId"`
	IotModuleStatus uint   `json:"iotModuleStatus"`
}

//下行通用
type DownJsonInfoUnify struct {
	LinkedMsgType       string                    `json:"linkedMsgType,omitempty"`
	ApplicationMsgType  string                    `json:"applicationMsgType,omitempty"`
	TlvMsgType          string                    `json:"tlvMsgType,omitempty"`
	TerminalMac         string                    `json:"terminalMac,omitempty"`
	GwMac               string                    `json:"gwMac,omitempty"`
	IotModuleId         string                    `json:"iotModuleId,omitempty"`
	RSSI                int8                      `json:"rssi,omitempty"`
	CharacterOpteration ParameterForCharacterDown `json:"characterOpteration,omitempty"`
	CharacterFind       CharacterInfo             `json:"characterInfo,omitempty"`
	Ctrl                int                       `json:"ctrl,omitempty"`
	DevConnInfo         DevConnection             `json:"devConnInfo,omitempty"`
	ServiceNode         ServiceCharacterNode      `json:"serviceNode,omitempty"`
	UUID                string                    `json:"uuid,omitempty"`
}

//终端设备信息
type TerminalInfo struct {
	TerminalName  string    `json:"terminalName,omitempty"`
	TerminalMac   string    `json:"terminalMac,omitempty"`
	GwMac         string    `json:"gwMac,omitempty"`
	IotModuleId   string    `json:"iotModuleId,omitempty"`
	RSSI          int8      `json:"rssi,omitempty"`
	SupportConn   bool      `json:"supportConn,omitempty"`
	ConnectStatus string    `json:"connectStatus,omitempty"`
	TimeStamp     time.Time `json:"timestamp,omitempty"`
	ConnHandle    string    `form:"connHandle" json:"connHandle" binding:"connHandle"`
}

//设备连接
//连接成功以后存储下来
type DevConnection struct {
	DevMac            string `form:"devMac" json:"devMac" binding:"devMac"`
	GwMac             string `form:"gwMac" json:"gwMac" binding:"gwMac"`
	ModuleId          string `form:"moduleId" json:"moduleId" binding:"moduleId"`
	ConnStatus        string `form:"connStatus" json:"connStatus" binding:"connStatus"`
	ConnHandle        string `form:"connHandle" json:"connHandle" binding:"connHandle"`
	PHY               string `form:"phy" json:"phy" binding:"phy"`
	MTU               string `form:"mtu" json:"mtu" binding:"mtu"`
	AddrType          uint8  `form:"addrType" json:"addrType" binding:"addrType"`
	OpType            uint8  `form:"opType" json:"opType" binding:"opType"`
	ScanType          uint8  `form:"scanType" json:"scanType" binding:"scanType"`
	ScanInterval      uint16 `form:"scanInterval" json:"scanInterval" binding:"scanInterval"`
	ScanWindow        uint16 `form:"scanWindow" json:"scanWindow" binding:"scanWindow"`
	ScanTimeout       uint16 `form:"scanTimeout" json:"scanTimeout" binding:"scanTimeout"`
	ConnInterval      uint16 `form:"connInterval" json:"connInterval" binding:"connInterval"`
	ConnLatency       uint16 `form:"connLatency" json:"connLatency" binding:"connLatency"`
	SupervisionWindow uint16 `form:"supervisionWindow" json:"supervisionWindow" binding:"supervisionWindow"`
}

//扫描所需参数
type ScanInfo struct {
	EnableScan   uint8  `form:"enableScan" json:"enableScan" binding:"enableScan"`
	ScanType     uint8  `form:"scanType" json:"scanType" binding:"scanType"`
	ScanInterval uint16 `form:"scanInterval" json:"scanInterval" binding:"scanInterval"`
	ScanWindow   uint16 `form:"scanWindow" json:"scanWindow" binding:"scanWindow"`
	ScanTimeout  uint16 `form:"ScanTimeout" json:"ScanTimeout" binding:"ScanTimeout"`
	GwMac        string `form:"gwMac"  json:"gwMac" binding:"gwMac"`
	IotModuleId  uint16 `form:"iotModuleId" json:"iotModuleId" binding:"iotModuleId"`
}

//响应web界面端
type ResultMessage struct {
	Code    int         `json:"code"`
	Data    interface{} `json:"data"`
	Message string      `json:"message"`
}

//设备主服务消息
type ServiceInfo struct {
	PrimaryService bool   `json:"primaryService" db:"primaryService"` //是否为主服务
	UUIDService    uint16 `json:"uuidService" db:"uuidService"`
	HandleService  uint16 `json:"handleService" db:"handleService"`
	DevMac         string `json:"devMac" db:"devMac"`
}

//handle请求
type CharacterInfo struct {
	DevMac      string `json:"devMac,omitempty"`
	StartHandle string `json:"startHandle,omitempty"`
	EndHandle   string `json:"ednHandle,omitempty"`
}

//RPCIotware
type RPCIotware struct {
	Device string `json:"device"`
	Data   string `json:"data"`
}

//模块复位下行
type RPCGatewayIotware struct {
	Device string     `json:"device"`
	Data   ModuleData `json:"data"`
}

type ModuleData struct {
	Id         int    `json:"id"`
	MethodName string `json:"method"`
	Para       Param  `json:"param"`
}

type Param struct {
	IotModuleId int `json:"PortID"`
}

//终端删除
type EventDeviceDeleteIotware struct {
	DeviceList []string `json:"deviceList"`
}

//特征操作请求参数
type ParameterForCharacterDown struct {
	CharacterHandle string `json:"characterHandle,omitempty"`
	Parameter       string `json:"parameter,omitempty"`
}

//TelemetryIotware
type TelemetryIotware struct {
	Device string `json:"device"`
	Data   string `json:"data"`
}

//ack
type NetworkInAckIotware struct {
	Device string `json:"device"`
	OK     bool   `json:"isok"`
}

//networkIn
type NetworkInIotware struct {
	Device string `json:"device"`
}

//存服务特征的最终节点
type ServiceCharacterNode struct {
	ServiceUUID     string `json:"serviceUUID,omitempty"`
	ServiceHandle   string `json:"serviceHandle,omitempty"`
	CharUUID        string `json:"charUUID,omitempty"`
	CharacterHandle string `json:"characterHandle,omitempty"` //
	CharacterValue  string `json:"characterValue,omitempty"`  //标准string存储方式
	CCCDHanle       string `json:"cccdHandle,omitempty"`      //
	CCCDHanleValue  string `json:"cccdHandleValue,omitempty"`
	Properties      string `json:"properties,omitempty"` //特征值属性位域
}

//(设备) 服务对应特征
type ServiceCharacterMap struct {
	ServiceMap map[string]map[string]ServiceCharacterNode `json:"serviceCharacterNode"`
}

//(设备) 特征对应服务
type CharacterServiceMap struct {
	CharacterMap map[string]ServiceCharacterNode `json:"characterserviceNode"`
}

// mqtt message
type GwMessageMqtt struct {
	Device string       `json:"device,omitempty"`
	Data   []DeviceData `json:"data,omitempty"`
}

type DeviceData struct {
	TS    int         `json:"ts,omitempty"`
	Value *InnerValue `json:"values,omitempty"`
}

type InnerValue struct {
	AliveTime  int             `json:"KeepAliveTime,omitempty"`
	ModuleInfo *IotModuleState `json:"ModuleState,omitempty"`
	Basic      *BasicInfo      `json:"BasicInfo,omitempty"`
}

type BasicInfo struct {
	Model string `json:"Model,omitempty"` //网关型号名
	SN    string `json:"SN,omitempty"`
	MAC   string `json:"MAC,omitempty"`
}

type IotModuleState struct {
	PortID int    `json:"PortID,omitempty"` //模块ID
	State  int    `json:"State,omitempty"`  //模块运行状态
	Model  string `json:"Model,omitempty"`  //模块型号
	SN     string `json:"SN,omitempty"`     //模块序列号
	MAC    string `json:"MAC,omitempty"`    //模块MAC
}

type GwMqtt struct {
	Device string `json:"device,omitempty"`
	Data   string `json:"data,omitempty"`
}

//设备专用 可以带有一些额外值的meteData如rssi，特征值handle等
type DevMessageMqtt struct {
	Device   string      `json:"device,omitempty"`
	Data     string      `json:"data,omitempty"`
	Metadata interface{} `json:"metadata,omitempty"`
}

//服务请求
type DeviceHttpMsg struct {
	Code    int         `json:"code"`
	Data    interface{} `json:"data"`
	Message string      `json:"message"`
}
